package com.sdleyou.treepro.common.task;

import com.sdleyou.treepro.common.service.UserManager;
import com.sdleyou.treepro.common.service.UserMissionManager;
import com.sdleyou.treepro.common.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.TimeZone;

@Component
@EnableScheduling
public class WaterScheduleTask {

    @Autowired
    private UserManager userManager;

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 自动生成水滴 每半小时执行一次
     */
    @Async("taskExecutor")
    @Scheduled(cron = "0 0/30 * * * ?")
    private void waterTasks() {
        userManager.updateWater();
        logger.info("waterTask 本次执行时间: {}",
                DateUtil.toString(DateUtil.getDateline(), "yyyy-MM-dd HH:mm:ss"));
    }
}